package com.touni.designpattern.filterpattern;

import com.touni.designpattern.filterpattern.criteria.Criteria;

import java.util.List;

/**
 * @ClassName : OrCriteria
 * @Description :
 * @Author : lwq
 * @Date: 2020-11-10 15:12
 */
public class OrCriteria implements Criteria {
    private Criteria criteria1;
    private Criteria criteria2;

    public OrCriteria(Criteria criteria1, Criteria criteria2){
        this.criteria1 = criteria1;
        this.criteria2 = criteria2;
    }

    @Override
    public List<PersonModel> filterPerson(List<PersonModel> personModelList) {
        List<PersonModel> personModels1 = criteria1.filterPerson(personModelList);
        List<PersonModel> personModels2 = criteria2.filterPerson(personModelList);
        for (PersonModel personModel : personModels2){
            if (!personModels1.contains(personModel)){
                personModels1.add(personModel);
            }
        }
        return personModels1;
    }
}
